//
//  ViewController.m
//  HCGDMap
//
//  Created by 1029523490@qq.com on 16/3/29.
//  Copyright © 2016年 1029523490@qq.com. All rights reserved.
//

#import "ViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapLocationKit/AMapLocationKit.h>

@interface ViewController ()<MAMapViewDelegate,AMapLocationManagerDelegate>

@property (nonatomic, strong)  MAMapView *mapView;
@property (nonatomic, strong) AMapLocationManager *locationManager;

@end

@implementation ViewController

- (MAMapView *)mapView{
    if (!_mapView) {
        _mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
        _mapView.delegate = self;
        _mapView.mapType = MAMapTypeStandard;
        _mapView.showTraffic= YES;
        [self.locationManager startUpdatingLocation];
        [_mapView setUserTrackingMode: MAUserTrackingModeFollow animated:YES];
        [self.view addSubview:_mapView];
    }
    return _mapView;
}

- (AMapLocationManager *)locationManager{
    if (!_locationManager) {
        
        _locationManager = [[AMapLocationManager alloc] init];
        _locationManager.delegate = self;
    }
    return _locationManager;
}
   

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  
    [self locationManager];
     [self mapView];
}

- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location
{
    NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
    }

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(31.982527, 118.735046);
    pointAnnotation.title = @"宏创科技";
    pointAnnotation.subtitle = @"国家广告产业园XXX";
    
    [self.mapView addAnnotation:pointAnnotation];
   

}

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
        annotationView.canShowCallout= YES;       //设置气泡可以弹出，默认为NO
        annotationView.animatesDrop = YES;        //设置标注动画显示，默认为NO
        annotationView.draggable = YES;        //设置标注可以拖动，默认为NO
        annotationView.pinColor = MAPinAnnotationColorPurple;
        return annotationView;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
